/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditWindow.java
 *
 * Created on Apr 10, 2011, 8:56:31 PM
 */

package GUI;

import Business.FrameHandler;
import Domain.DataManager;
import Domain.UserClient.ButtonsFunctions;
import java.util.Vector;
import objects.Trd;

/**
 *
 * @author Inbal
 */
public class EditWindow extends javax.swing.JFrame {
    private Trd _trd;
    private String _msgTitle;
    /** Creates new form EditWindow */
    public EditWindow(Trd trd,String title, String msg) {
        this._trd = trd;
        this._msgTitle = title;
        initComponents();
      
        jTextArea1.setText(msg);
        
     
        jTextArea1.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        chooseFourmLabel = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        chooseFourmLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Edit Message");

        chooseFourmLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        chooseFourmLabel.setForeground(new java.awt.Color(0, 102, 102));
        chooseFourmLabel.setText("Edit Message content:");

        jButton1.setLabel("Change Message");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        chooseFourmLabel2.setFont(new java.awt.Font("Tahoma", 0, 18));
        chooseFourmLabel2.setForeground(new java.awt.Color(0, 0, 204));
        chooseFourmLabel2.setText("Edit Message");

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(chooseFourmLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 328, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(107, 107, 107)
                        .addComponent(chooseFourmLabel2)))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chooseFourmLabel2)
                .addGap(18, 18, 18)
                .addComponent(chooseFourmLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String content = jTextArea1.getText();
        if(content.isEmpty()) {
            String error = "You have to enter some text in the new message";
            FrameHandler.getFrameHandler().showErrorMessage(error);
        } 
        else{
            ButtonsFunctions.getButtonsFunctions().processEditMessage(this._trd.getThreadName(),_msgTitle, content);
            if(DataManager.getDataManager().getSuccessOrFailure() == DataManager.FAILURE)
                return;
        
            String currForum = ButtonsFunctions.getButtonsFunctions().getCurrentForum();
            ButtonsFunctions.getButtonsFunctions().processGetThreads(currForum);
            String forum = DataManager.getDataManager().getCurrForum();
            Vector<Trd> threads = DataManager.getDataManager().getVectorThreads();
            FrameHandler.getFrameHandler().changeCurrentFrame(new Forum(threads));
            this.dispose();
        }
}//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               // new EditWindow().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel chooseFourmLabel;
    private javax.swing.JLabel chooseFourmLabel2;
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables

}
